package com.whq.thrift.api.web.admin.service.admin.impl;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.whq.thrift.api.common.spring.datasource.DataSourceContextHolder;
import com.whq.thrift.api.web.admin.db.admin.AlertThreshold;
import com.whq.thrift.api.web.admin.db.admin.AlertThresholdMapper;
import com.whq.thrift.api.web.admin.service.admin.AlertThresholdService;

@Service
public class AlertThresholdServiceImpl implements AlertThresholdService {
	@Autowired
	private AlertThresholdMapper alertThresholdMapper;

	public void addRecord(AlertThreshold record) {
		DataSourceContextHolder.set("dataSourceAdmin");
		if (record == null) {
			return;
		}
		Date now = new Date();
		record.setCreateTime(now);
		this.alertThresholdMapper.addRecord(record);
	}

	public List<AlertThreshold> findRecordsByMap(Map<String, Object> whereParams, int beginIndex, int maxCount) {
		DataSourceContextHolder.set("dataSourceAdmin");
		if (whereParams == null) {
			whereParams = new HashMap<String, Object>(0);
		}
		whereParams.put("beginIndex", beginIndex);
		whereParams.put("maxCount", maxCount);
		return this.alertThresholdMapper.findRecordsByMap(whereParams);
	}

	public void updateRecord(AlertThreshold record) {
		DataSourceContextHolder.set("dataSourceAdmin");
		if (null == record) {
			return;
		}

		Date now = new Date();
		record.setUpdateTime(now);

		this.alertThresholdMapper.updRecord(record);

	}

	public void deleteRecord(String id) {
		DataSourceContextHolder.set("dataSourceAdmin");
		this.alertThresholdMapper.delRecord(id);

	}

	public int findRecordCount(Map<String, Object> whereParams) {
		DataSourceContextHolder.set("dataSourceAdmin");

		return this.alertThresholdMapper.findRecordsCount(whereParams);
	}

	public AlertThreshold findRecordById(int id) {
		DataSourceContextHolder.set("dataSourceAdmin");
		return this.alertThresholdMapper.getRecordByKey(id);
	}

	public List<AlertThreshold> findAlertThresholdMap(Map<String, Object> whereParams) {
		DataSourceContextHolder.set("dataSourceAdmin");
		if (whereParams == null) {
			whereParams = new HashMap<String, Object>(0);
		}
		return this.alertThresholdMapper.findAlertThresholdSql(whereParams);
	}

}
